package com.gz.servlet.annotation;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//注解方式创建servlet(这种方法不需要修改web.xml)
//目录匹配，"/ok1/*"表示可以访问http://localhost:8080/servlet/ok1/任意值的网站,
// 如http://localhost:8080/servlet/ok1/asds/sd/sd等等
//扩展名匹配,"*.action"(注意这个不能加/,否则报错 )，这时可以访问http://localhost:8080/servlet/任意值.action
@WebServlet(urlPatterns = {"/ok1","/ok2"})//表示可以访问http://localhost:8080/servlet/ok1或者
                                                    //http://localhost:8080/servlet/ok2
public class HelloServlet extends HttpServlet {
    //看源码就发现，doGet()最终还是用到了service()方法
    public void doGet(HttpServletRequest req, HttpServletResponse resp){
        System.out.println("注解方式 Helloservlet的 doGet被调用");
    }
    public void doPost(HttpServletRequest req, HttpServletResponse resp){
        System.out.println("注解方式 Helloservlet的 doPost被调用");
    }
}
